package ui;

import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Properties;

import javax.swing.JFrame;

import org.apache.log4j.Logger;

import animations.DrawSheet;

import utility.AppUtilities;

public class WorkBean extends JFrame implements MyBeanIfc {
	private static final Logger LOGGER = Logger.getLogger(WorkBean.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 3955747619755068395L;

	protected final AppUtilities utilities;
	protected Properties prop; // hold properties file
	protected final MyModelIfc model;

	public WorkBean(String title) throws HeadlessException {
		super(title);
		this.utilities = AppUtilities.createAppUtilities();
		this.prop = utilities.openProperties(utilities.openConfigurationFile("ui.properties"));
		this.model = new WorkModel();
	}

	@Override
	public void addNotify() {
		initialize();
		super.addNotify();
	}

	@Override
	public void initialize() {
		int w = Integer.valueOf(prop.getProperty("main.scr.w", "480"));
		int h = Integer.valueOf(prop.getProperty("main.scr.h", "320"));

		this.setSize(w, h);
		this.setLayout(new GridLayout());
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);

		// Fastened components
		DrawSheet drawSheet = new DrawSheet();
		drawSheet.setSize(this.getSize());
		this.getContentPane().add(drawSheet);

		// Add to store
		try {
			utilities.put(getClass().getName(), this);
		}catch (Exception e) {
			LOGGER.warn(e.getMessage(), e.getCause());
		}

		// On closing
		addWindowListener(new ThisWindow());

	}

	@Override
	public void updateBean() {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateModel() {
		// TODO Auto-generated method stub

	}
}

class ThisWindow extends WindowAdapter {

	@Override
	public void windowClosing(WindowEvent e) {
		super.windowClosing(e);
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowClosed(e);
	}

}
